<template>
  <div class="box" v-for="item in productList" :key="item.id">
    <h2>{{ item.name }}</h2>
    <div class="container">
      <div class="left">
        <RouterLink to="/" class="leftLink">
          <img v-img-lazy="item.picture" alt="" />
          <span>{{ item.saleInfo }}</span>
        </RouterLink>
      </div>

      <div class="right">
        <div class="item" v-for="i in item.goods" :key="i.id">
          <GoodsItem :goods="i" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="ComponentName">
import { getGoodsAPI } from '@/api/home'
import { onMounted, ref } from 'vue'
import GoodsItem from './GoodsItem.vue'

const productList = ref([])
const getGoodsList = async () => {
  const res = await getGoodsAPI()
  productList.value = res.result
}
onMounted(() => {
  getGoodsList()
})
</script>

<style scoped lang="scss">
.box {
  height: 100%;
  width: 100%;
  margin-top: 20px;
  padding: 0 100px;
  background: #ffffff;
  h2 {
    padding: 20px 0;
  }
  .container {
    height: 100%;
    width: 100%;
    height: 600px;
    display: flex;
    flex-flow: row nowrap;
    gap: 20px;

    .left {
      width: 350px;
      height: 100%;
      position: relative;
      overflow: hidden;
      .leftLink {
        width: 100%;
        height: 100%;
        span {
          position: absolute;
          top: 0;
          left: 0;
          width: 100%;
          height: 100%;
          background: rgba(0, 0, 0, 0.5);
          color: #fff;
          font-size: 20px;
          text-align: center;
          line-height: 220px;
          z-index: 999;
        }
        img {
          width: 100%;
          height: 100%;
        }

        &:hover {
          span {
            display: none;
          }

          img {
            transform: scale(1.05);
            transition: all 0.3s;
          }
        }
      }
    }
    .right {
      display: flex;
      flex-flow: row wrap;
      justify-content: flex-start;
      align-content: flex-start;
      gap:  0px 60px;
      width: calc(100% - 400px);
      height: 100%;
      .item {
        width: calc(25% - (60px * 3) / 4);
        height: 300px;
        &:hover {
          transform: translateY(-10px);
          transition: all 0.3s ease-in-out;
        }
      }
    }
  }
}
</style>
